package com.springseries.websocket.controller;

import com.springseries.websocket.common.Constants;
import com.springseries.websocket.message.Message;
import com.springseries.websocket.message.WebMessage;
import com.springseries.websocket.service.WebsocketService;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Controller
public class WsController {

    @Resource
    private WebsocketService service;

    @MessageMapping(Constants.FORE_TO_SERVER_PATH)
    @SendTo(Constants.PRODUCER_PATH)
    public Message say(WebMessage msg){
        List<String > users = new ArrayList<>();
        users.add("d892bf12bf7d11e793b69c5c8e6f60fb");
        service.sendMsg(users,new Message("hello"));

        return new Message("welcome,"+msg.getName()+"!");
    }

    @RequestMapping("/ws")
    public String wsPage(){
        return "welcome";
    }
}
